package com.zzzs.threaddemo;

import org.junit.jupiter.api.Test;

/**
 * @author zhu_shuai
 * @since 2021/6/23
 */
public class WaitDemo {

    @Test
    void t1() throws InterruptedException {
        Object lock = new Object();

        MyRunable2 myRunable2 = new MyRunable2(lock);
        Thread thread = new Thread(myRunable2);
        thread.start();

        Thread.sleep(3*1000);

        lock.notify();
    }

    class MyRunable2 implements Runnable{

        private final Object lock;

        public MyRunable2(Object lock) {
            this.lock = lock;
        }

        @Override
        public void run() {
            try {
                synchronized (lock) {
                    System.out.println("start wait");
                    Thread.sleep(20*1000);
                    lock.wait(10*1000);
                }
                System.out.println("ent wait");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}


